Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 3 - Geometric Styles / Using Geometric Styles


Adding Standard Caps to a Shape

Two types of caps that you may frequently want to add to your shapes are the round cap and the square cap. The sample function in Listing 3-10 shows how to create these types of caps.

For a round cap, you need to create a semicircle, which you can do using the library function NewArc. To fit the end of a contour, the bounds of this semicircle must be set as follows:

gxRectangle roundCapBounds = {-fl(.5), -fl(.5), fl(.5), fl(.5)};
and the semicircle must start at 180 degrees and span a 180 degree arc:

gxRoundCap = NewArc(&roundCapBounds, ff(180), ff(180), true);
For a square cap to fit the end of a contour, its bounds must be set as follows:

gxRectangle squareCapBounds = {-ff(.5), -ff(.5), ff(0), ff(.5)};
Listing 3-10 shows how to create a round cap and a square cap for the curve shape from previous examples.

Listing 3-10 Adding round caps and square caps to a curve

void CreateMyShape(void)
{
   gxShape  aCurve, gxRoundCap, gxSquareCap;

   static gxCurve curveGeometry = {ff(25),  ff(125), 
                                   ff(100), 0, 
                                   ff(225), ff(125)};
   
   static gxRectangle roundCapBounds = {-fl(.5), -fl(.5), 
                                        fl(.5), fl(.5)};

   static gxRectangle squareCapBounds = {-ff(.5), -ff(.5), 
                                         ff(0), ff(.5)};
   
   gxCapRecord theCapRecord;


   aCurve = GXNewCurve (&curveGeometry);
      
   gxRoundCap = NewArc(&roundCapBounds, ff(180), ff(180), true);
   gxSquareCap = GXNewRectangle(&squareCapBounds);

   theCapRecord.startCap = gxRoundCap;
   theCapRecord.endCap = gxSquareCap;
   theCapRecord.attributes = gxNoAttributes;

   GXSetShapeCap(aCurve, &theCapRecord);
   
   GXDisposeShape(gxRoundCap);
   GXDisposeShape(gxSquareCap);
   
   GXSetShapePen(aCurve, ff(10));
   
   GXDrawShape(aCurve);
   
   GXDisposeShape(aCurve);
}
Figure 3-54 shows the result of this sample function.

Figure 3-54 Round and square caps

Notice that QuickDraw GX rotates and resizes the caps to fit the contour.

The sections "The Cap Structure" on page 3-99 and "Cap Attributes" on page 3-101 describe the cap structure and the cap attributes in more detail, and the section "Getting and Setting Caps" beginning on page 3-123 describes the functions you can use to manipulate caps.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996